//
//  MyOrderDetailViewController.m
//  NiuNiuPacking
//
//  Created by Janny on 14-10-1.
//  Copyright (c) 2014年 Reseek. All rights reserved.
//

#import "MyOrderDetailViewController.h"
#import "QREncoder.h"
#import "StopCarRouteViewController.h"
#import "QRCodeImageShowViewController.h"
#import "EvaluationOrderViewController.h"

@interface MyOrderDetailViewController ()

@end

@implementation MyOrderDetailViewController

@synthesize state;
//@synthesize qrCodeScanViewController;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if(self.lbState!=nil && self.state){
        self.lbState.text = self.state;
        if([self.state isEqualToString: @"新订单"]){
            [self newOrderInitializeUI];
        }else if([self.state isEqualToString: @"已入场"]){
            [self alreadyEntranceInitializeUI];
        }else if([self.state isEqualToString: @"已支付"]){
            [self alreadyPayInitializeUI];
        }else if([self.state isEqualToString: @"已评价"]){
            [self alreadyEvaluationInitializeUI];
        }
    }
    
}

//new order initalize
-(void)newOrderInitializeUI{
    //label
    self.labelOrderState.hidden = NO;
    self.lbState.hidden = NO;
    
    self.labelStopDanJia.hidden = NO;
    self.stopCarDanJia.hidden = NO;
    
    self.labelCarPaiNumber.hidden = NO;
    self.carNumber.hidden = NO;
    
    self.labelCarWeiNumber.hidden = YES;
    self.carWeiNumber.hidden = YES;
    
    self.labelInChangTime.hidden = YES;
    self.lbInChangTime.hidden = YES;
    
    self.labelStopCarTime.hidden = YES;
    self.stopCarTime.hidden = YES;
    
    self.labelStopCarJinE.hidden = YES;
    self.stopCarJinE.hidden = YES;
    
    self.labelYiFuJinE.hidden = YES;
    self.yiFuJinE.hidden = YES;
    
    self.labelYingFuJinE.hidden = YES;
    self.yingFuJinE.hidden = YES;
    
    self.labelCreateTime.hidden = NO;
    self.lbCreateTime.hidden = NO;
    
    //buttom
    self.btnStopCarLuXIan.hidden = NO;
    self.btnOpenOrderQRCode.hidden = YES;
    self.btnCancelOrder.hidden = NO;
    self.btnCarInChangScanQRCode.hidden = NO;
    self.btnCarOutChangScanQRCode.hidden = YES;
    self.btnPingJiaOrder.hidden = YES;
    
    
    //move control
    CGRect view = self.viewButtons.frame;
    view.origin.y = 258;
    
}

//已入闸
-(void)alreadyEntranceInitializeUI{
    //label
    self.labelOrderState.hidden = NO;
    self.lbState.hidden = NO;
    
    self.labelStopDanJia.hidden = NO;
    self.stopCarDanJia.hidden = NO;
    
    self.labelCarPaiNumber.hidden = NO;
    self.carNumber.hidden = NO;
    
    self.labelCarWeiNumber.hidden = NO;
    self.carWeiNumber.hidden = NO;
    
    self.labelInChangTime.hidden = NO;
    self.lbInChangTime.hidden = NO;
    
    self.labelStopCarTime.hidden = YES;
    self.stopCarTime.hidden = YES;
    
    self.labelStopCarJinE.hidden = YES;
    self.stopCarJinE.hidden = YES;
    
    self.labelYiFuJinE.hidden = NO;
    self.yiFuJinE.hidden = NO;
    
    self.labelYingFuJinE.hidden = YES;
    self.yingFuJinE.hidden = YES;
    
    self.labelCreateTime.hidden = YES;
    self.lbCreateTime.hidden = YES;
    
    //buttom
    self.btnStopCarLuXIan.hidden = NO;
    self.btnOpenOrderQRCode.hidden = NO;
    self.btnCancelOrder.hidden = YES;
    self.btnCarInChangScanQRCode.hidden = YES;
    self.btnCarOutChangScanQRCode.hidden = NO;
    self.btnPingJiaOrder.hidden = YES;
    
    
    //move control
    CGRect view = self.viewButtons.frame;
    view.origin.y = 258;
    
}

//已支付
-(void)alreadyPayInitializeUI{
    //label
    self.labelOrderState.hidden = NO;
    self.lbState.hidden = NO;
    
    self.labelStopDanJia.hidden = NO;
    self.stopCarDanJia.hidden = NO;
    
    self.labelCarPaiNumber.hidden = NO;
    self.carNumber.hidden = NO;
    
    self.labelCarWeiNumber.hidden = NO;
    self.carWeiNumber.hidden = NO;
    
    self.labelInChangTime.hidden = YES;
    self.lbInChangTime.hidden = YES;
    
    self.labelStopCarTime.hidden = NO;
    self.stopCarTime.hidden = NO;
    
    self.labelStopCarJinE.hidden = NO;
    self.stopCarJinE.hidden = NO;
    
    self.labelYiFuJinE.hidden = NO;
    self.yiFuJinE.hidden = NO;
    
    self.labelYingFuJinE.hidden = NO;
    self.yingFuJinE.hidden = NO;
    
    self.labelCreateTime.hidden = YES;
    self.lbCreateTime.hidden = YES;
    
    //buttom
    self.btnStopCarLuXIan.hidden = NO;
    self.btnOpenOrderQRCode.hidden = NO;
    self.btnCancelOrder.hidden = YES;
    self.btnCarInChangScanQRCode.hidden = YES;
    self.btnCarOutChangScanQRCode.hidden = YES;
    self.btnPingJiaOrder.hidden = NO;
    
    
    //move control
    CGRect view = self.viewButtons.frame;
    view.origin.y = 258;
    
}

//已评价
-(void)alreadyEvaluationInitializeUI{
    //label
    self.labelOrderState.hidden = NO;
    self.lbState.hidden = NO;
    
    self.labelStopDanJia.hidden = NO;
    self.stopCarDanJia.hidden = NO;
    
    self.labelCarPaiNumber.hidden = NO;
    self.carNumber.hidden = NO;
    
    self.labelCarWeiNumber.hidden = NO;
    self.carWeiNumber.hidden = NO;
    
    self.labelInChangTime.hidden = YES;
    self.lbInChangTime.hidden = YES;
    
    self.labelStopCarTime.hidden = NO;
    self.stopCarTime.hidden = NO;
    
    self.labelStopCarJinE.hidden = NO;
    self.stopCarJinE.hidden = NO;
    
    self.labelYiFuJinE.hidden = NO;
    self.yiFuJinE.hidden = NO;
    
    self.labelYingFuJinE.hidden = NO;
    self.yingFuJinE.hidden = NO;
    
    self.labelCreateTime.hidden = YES;
    self.lbCreateTime.hidden = YES;
    
    //buttom
    self.btnStopCarLuXIan.hidden = NO;
    self.btnOpenOrderQRCode.hidden = NO;
    self.btnCancelOrder.hidden = YES;
    self.btnCarInChangScanQRCode.hidden = YES;
    self.btnCarOutChangScanQRCode.hidden = YES;
    self.btnPingJiaOrder.hidden = YES;
    
    
    //move control
    CGRect view = self.viewButtons.frame;
    view.origin.y = 258;
}

StopCarRouteViewController *stopCarRouteViewShow=nil;

//停车路线按钮事件
- (IBAction)btnStopCarLuXian_Click:(id)sender {
    
    stopCarRouteViewShow=[self.storyboard instantiateViewControllerWithIdentifier:@"StopCarRouteViewController"];
    
    [stopCarRouteViewShow setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    
    [self presentViewController:stopCarRouteViewShow animated:YES completion:^{
        //arrive new page event
    }];
}

- (IBAction)openOrder2WeiMa_Click:(id)sender {
    UIImage *qrCodeImg = [QREncoder encode:@"www.re-seek.com"];
    QRCodeImageShowViewController *qrcodeImgShow=[self.storyboard instantiateViewControllerWithIdentifier:@"QRCodeImageShowView"];
    qrcodeImgShow.QRCodeImage = qrCodeImg;
    [self presentViewController:qrcodeImgShow animated:YES completion:^{
        //arrive new page event
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnCarOut_Click:(id)sender {
    
}

- (IBAction)btnCarIn_Click:(id)sender {
}

QRCodeScanViewController *qrCodeScanViewController =nil;

- (IBAction)btnCarInScanQrCode_Click:(id)sender {
    //go to QRCode scan page
    qrCodeScanViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"QRCodeScanViewController"];
    
    [qrCodeScanViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    
    [self presentViewController:qrCodeScanViewController animated:YES completion:^{
        //arrive new page event
    }];
}

- (IBAction)btnCancelOrder_Click:(id)sender {
    
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"订单取消确认"
                         message:@"您确认要取消订单吗？"
                         delegate:self
                         cancelButtonTitle:@"确定"
                                        otherButtonTitles:@"取消",nil];
    [alertView show];
    
    
}

EvaluationOrderViewController *evaluationOrderViewController =nil;

- (IBAction)btnEvaluationOrder_Clcik:(id)sender {
    evaluationOrderViewController=[self.storyboard instantiateViewControllerWithIdentifier:@"EvaluationOrderViewController"];
    
    [self presentViewController:evaluationOrderViewController animated:YES completion:^{
        //arrive new page event
    }];
}



-(void)viewWillAppear:(BOOL)animated{
    //from qrcodescan page back
    if(qrCodeScanViewController!=nil){
        if(qrCodeScanViewController.QRCode!=nil){
            //get qrcode string
            
        }
    }
}

-(void) passParameterToView:(NSString *) value{
    self.state = value;
    if(self.lbState!=nil){
        self.lbState.text = value;
    }
}

//order cancel affirm go back
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0){
        //remove selected order
        NSLog(@"remove selected order");
    }
    else if(buttonIndex == 1){
        NSLog(@"cancel");
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */



- (void)dealloc {
    [_orderTitle release];
    [_orderAddress release];
    [_stopCarDanJia release];
    [_carNumber release];
    [_carWeiNumber release];
    [_stopCarTime release];
    [_stopCarJinE release];
    [_yiFuJinE release];
    [_yingFuJinE release];
    [_lbState release];
    [_btnStopCarLuXIan release];
    [_btnOpenOrderQRCode release];
    [_btnCarOutChangScanQRCode release];
    [_btnCarInChangScanQRCode release];
    [_btnPingJiaOrder release];
    [_btnCancelOrder release];
    [_labelStopCarTime release];
    [_labelStopCarJinE release];
    [_labelYiFuJinE release];
    [_labelYingFuJinE release];
    [_labelOrderState release];
    [_labelStopDanJia release];
    [_labelCarPaiNumber release];
    [_labelCarWeiNumber release];
    [_labelCreateTime release];
    [_lbCreateTime release];
    [_viewButtons release];
    [_labelInChangTime release];
    [_lbInChangTime release];
    [super dealloc];
}
@end
